class code1 {
    //归并排序
    int[] tmp;
    public int[] sortArray(int[] nums) {
        tmp = new int[nums.length];
        mergeSort(nums,0,nums.length-1);
        return nums;
    }
    public void mergeSort(int[] nums,int left,int right) {
        //1.出口
        if(left>=right) return;
        //2.求中点
        int mid = (left+right)/2;
        //3.左右分别排序
        mergeSort(nums,left,mid);
        mergeSort(nums,mid+1,right);
        //4.合并两个数组
        int cur1=left,cur2=mid+1,i=0;
        while(cur1<=mid&&cur2<=right) {
            tmp[i++] = nums[cur1]<nums[cur2]?nums[cur1++]:nums[cur2++];
        }
        //处理剩下的元素
        while(cur1<=mid) tmp[i++] = nums[cur1++];
        while(cur2<=right) tmp[i++] = nums[cur2++];

        //映射数组
        for(int j=left;j<=right;j++) {
            nums[j] = tmp[j-left];
        }
    }
}